// ignore_for_file: file_names

import 'package:flutter/material.dart';

class GridViewDemo1 extends StatelessWidget {
  const GridViewDemo1({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('GridView案例1'),
        backgroundColor: Colors.red,
      ),
      body: GridView(
        gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
            // 侧轴方向子元素的个数
            crossAxisCount: 2,
            // 主轴(垂直)方向子元素间距
            mainAxisSpacing: 5,
            // 侧轴(水平)方向子元素间距
            crossAxisSpacing: 5,
            // 子元素宽高比，默认宽高相同 1: 1
            childAspectRatio: 4 / 3),
        children: [
          Container(
            color: Colors.green,
            alignment: Alignment.center,
            child: const Text('FLUTTER DART 1'),
          ),
          Container(
            color: Colors.pink,
            alignment: Alignment.center,
            child: const Text('FLUTTER DART 2'),
          ),
          Container(
            color: Colors.blue,
            alignment: Alignment.center,
            child: const Text('FLUTTER DART 3'),
          ),
          Container(
            color: Colors.yellow,
            alignment: Alignment.center,
            child: const Text('FLUTTER DART 4'),
          ),
          Container(
            color: Colors.cyan,
            alignment: Alignment.center,
            child: const Text('FLUTTER DART 5'),
          ),
          Container(
            color: Colors.green,
            alignment: Alignment.center,
            child: const Text('FLUTTER DART 6'),
          )
        ],
      ),
    );
  }
}
